package de.uebungen.grabo;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;

import javax.swing.JLabel;
import javax.swing.JPanel;

import de.fhwgt.dionarap.model.objects.*;



@SuppressWarnings("serial")
public class Spielfeld extends JPanel {

	private static int x = 10;
	private static int y = 10;
	private JLabel[][] felder = new JLabel[10][10];
	
	public Spielfeld() {
		Dimension dim = new Dimension();
		dim.setSize(50, 50);

		
		this.setLayout(new GridLayout(x, y));
		for(int i = 0; i < y; i++ ){
			for(int j = 0; j < x; j++){
				felder[i][j] = new JLabel();
				felder[i][j].setPreferredSize(dim);
				felder[i][j].setOpaque(true);
				if((i+j)%2 == 0) {
					felder[i][j].setBackground(new Color(50, 70, 84));
				}
				else {
					felder[i][j].setBackground(new Color(156, 153, 133));
				}
				this.add(felder[i][j]);
			}
	
		}

	}
	
	public void drawElements(AbstractPawn[] object) 
	{
		int len = object.length;
		for(int i = 0; i < len; i++)
		{
			int tmp = i;
			JLabel feld = this.felder[object[tmp].getY()][object[tmp].getX()];
			
			if(object[tmp] instanceof Player)
			{
				feld.setText("P");
			}
			
			if(object[tmp] instanceof Ammo)
			{
				feld.setText("A");
			}
			
			if(object[tmp] instanceof Opponent)
			{
				feld.setText("O");
			}
			
			if(object[tmp] instanceof Obstacle)
			{
				feld.setText("H");
			}
			
			if(object[tmp] instanceof Destruction)
			{
				feld.setText("*");
			}
			
			if(object[tmp] instanceof Vortex)
			{
				feld.setBackground(new Color(30,42,51));
			}
		}
	}
	public void clear()
	{
		for (int y = 0; y < this.felder.length; y++) {
			for (int x = 0; x < this.felder[y].length; x++) {
				JLabel feld = this.felder[y][x];
				feld.setText(null);
			}
		}
	}

}